package com.amc.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "AMC_ORDER")
public class Order {
	@Id
	@GeneratedValue(generator = "PK_ORDER_UUID")
	@GenericGenerator(name = "PK_ORDER_UUID", strategy = "uuid")
	@Column(name = "order_id")
	private String orderId;

	@OneToOne(targetEntity = Merchant.class)
	@JoinColumn(name = "merchant_id")
	private Merchant merchant;

	@OneToOne(targetEntity = Customer.class)
	@JoinColumn(name = "customer_id")
	private Customer customer;

	@OneToOne(targetEntity = Address.class)
	@JoinColumn(name = "address_id")
	private Address address;

	@Column(name = "order_status")
	private int orderStatus;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time")
	private Date createTime;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "confirm_time")
	private Date confirmTime;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "finish_time")
	private Date finishTime;

	@OneToMany(targetEntity = OrderFood.class, cascade = CascadeType.ALL)
	private Set<OrderFood> orderFood = new HashSet<>();

	public Order(String orderId, Merchant merchant, Customer customer,
			Address address, int orderStatus, Date createTime,
			Date confirmTime, Date finishTime, Set<OrderFood> orderFood) {
		super();
		this.orderId = orderId;
		this.merchant = merchant;
		this.customer = customer;
		this.address = address;
		this.orderStatus = orderStatus;
		this.createTime = createTime;
		this.confirmTime = confirmTime;
		this.finishTime = finishTime;
		this.orderFood = orderFood;
	}

	public Order() {
		super();
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public Merchant getMerchant() {
		return merchant;
	}

	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Set<OrderFood> getOrderFood() {
		return orderFood;
	}

	public void setOrderFood(Set<OrderFood> orderFood) {
		this.orderFood = orderFood;
	}

	public int getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(int orderStatus) {
		this.orderStatus = orderStatus;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getConfirmTime() {
		return confirmTime;
	}

	public void setConfirmTime(Date confirmTime) {
		this.confirmTime = confirmTime;
	}

	public Date getFinishTime() {
		return finishTime;
	}

	public void setFinishTime(Date finishTime) {
		this.finishTime = finishTime;
	}

	@Override
	public String toString() {
		return "Order [orderId=" + orderId + ", merchant=" + merchant
				+ ", customer=" + customer + ", address=" + address
				+ ", orderStatus=" + orderStatus + ", createTime=" + createTime
				+ ", confirmTime=" + confirmTime + ", finishTime=" + finishTime
				+ ", orderFood=" + orderFood + "]";
	}
	
	
	

}
